package com.xuexiang.xui_lib.component.alpha;

import ohos.agp.components.AttrSet;
import ohos.agp.components.StackLayout;
import ohos.app.Context;

public class XUIAlphaFrameLayout extends StackLayout {
    private IAlphaViewHelper mAlphaViewHelper;
    public AttrSet attrSet;
    public XUIAlphaFrameLayout(Context context) {
        this(context,null);
    }

    public XUIAlphaFrameLayout(Context context, AttrSet attrSet) {
        this(context, attrSet,null);
    }

    public XUIAlphaFrameLayout(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        this.attrSet = attrSet;
    }

    private IAlphaViewHelper getAlphaViewHelper() {
        if (mAlphaViewHelper == null) {
            mAlphaViewHelper = new XUIAlphaViewHelper(this,attrSet);
        }
        return mAlphaViewHelper;
    }

    @Override
    public void setPressState(boolean pressed) {
        super.setPressState(pressed);
        getAlphaViewHelper().onPressedChanged(this, pressed);
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        getAlphaViewHelper().onEnabledChanged(this, enabled);
    }

    /**
     * 设置是否要在 press 时改变透明度
     *
     * @param changeAlphaWhenPress 是否要在 press 时改变透明度
     */
    public void setChangeAlphaWhenPress(boolean changeAlphaWhenPress) {
        getAlphaViewHelper().setChangeAlphaWhenPress(changeAlphaWhenPress);
    }

    /**
     * 设置是否要在 disabled 时改变透明度
     *
     * @param changeAlphaWhenDisable 是否要在 disabled 时改变透明度
     */
    public void setChangeAlphaWhenDisable(boolean changeAlphaWhenDisable) {
        getAlphaViewHelper().setChangeAlphaWhenDisable(changeAlphaWhenDisable);
    }
}
